package com.zj.filedemo;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getFilePath();
    }

    /* Checks if external storage is available for read and write */
    public boolean isExternalStorageWritable() {
        String state = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(state)) {
            return true;
        }
        Log.e(TAG, "isExternalStorageWritable: " + state);
        return false;
    }

    private void getFilePath() {
        if (!isExternalStorageWritable()) {
            return;
        }

        String mainDir = Environment.getExternalStorageDirectory().getAbsolutePath();

        String dcimDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
        String pictureDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();

        String fileDir = getExternalFilesDir(null).getAbsolutePath();

        String movieDir = getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath();
        String documentDir = getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();

        Log.e(TAG, "getFilePath: " + mainDir);

        Log.e(TAG, "getFilePath: " + pictureDir);
        Log.e(TAG, "getFilePath: " + dcimDir);

        Log.e(TAG, "getFilePath: " + fileDir);

        Log.e(TAG, "getFilePath: " + movieDir);
        Log.e(TAG, "getFilePath: " + documentDir);
    }
}
